package test.dao;

import org.nutz.lang.Lang;

import test.bean.User;

import com.ixion.mongo.EntityMapping;
import com.ixion.mongo.dao.MongoDao;
import com.ixion.mongo.utils.MongoClientPool;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

public class UserDao extends MongoDao<User> {

	@Override
	protected void init() {
		mapping = new EntityMapping<User>() {

			@Override
			public DBObject toDBObject(User t) {
				return MongoClientPool.obj2dbo(t);
			}

			@Override
			public DBCollection getCollection() {
				return MongoClientPool.getCollection(User.class);
			}

			@Override
			public User get(DBObject object) {
				return Lang.map2Object(MongoClientPool.dbo2map(object), User.class);
			}
		};
		collection = mapping.getCollection();
	}

}
